#!/usr/bin/python3
# -*- coding: utf-8 -*-

import pandas as pd
import numpy  as np

eps = 1e-8

def signal(*args):
    # Bias_v3
    df = args[0]
    n = args[1]
    factor_name = args[2]

    ma = df['close'].rolling(n, min_periods=1).mean()
    # will output nan, / 0.03 to normalize data
    df[factor_name] = np.log((df['close'] / (ma + eps))) / 0.03

    return df
